package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public interface OrdersMapper {
    void insert(Orders orders);


    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id =#{orderId}")
    Orders getById(Long orderId);

    /**
     * 根据状态统计订单数量
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 定时任务，每分钟检查一次是否有超时未支付的订单
     *
 * @param status
 * @param orderTime
     * @return
     * @author heiheiheng
     * @create 2025/8/12
     **/
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> selectByStatusAndOrderTime(Integer status, LocalDateTime orderTime);

    /**
     * 统计每日营业额
     * 
 * @param map
     * @return 
     * @author heiheiheng
     * @create 2025/8/13
     **/
    @Select("select sum(amount) from orders where status = #{status} and order_time between #{begin} and #{end}")
    Double sumByMap(Map map);

    /**
     * 统计订单数量
     *
 * @param map
     * @return
     * @author heiheiheng
     * @create 2025/8/13
     **/
    Integer countBtMap(Map map);

    /**
     * 统计前十菜品销量
     *
     * @param map
     * @return
     * @author heiheiheng
     * @create 2025/8/13
     **/
    @MapKey("name")
    List<Map> sumTop10(Map map);


    /**
     * 查询订单管理数据
     *
 * @param map
     * @return
     * @author heiheiheng
     * @create 2025/8/13
     **/
    Integer countByMap(Map map);
}
